<template>
	<view class="public-trends">
		<nav-header title="发布帖子" showback="true" navBackcolor="transparent"></nav-header>
		<view class="public-trends-main">
			<view class="public-trends-main-input">
				<textarea v-model="text" placeholder="请输入~" maxlength="200" />
				<view class="public-trends-main-input-max">
					{{text.length}}/200
				</view>
			</view>
			<view class="public-trends-main-pic u-flex">
				<view class="public-trends-main-pic-item">
					<image :src="item" style="height: 136rpx;width: 136rpx;" mode="" v-for="(item,index) in imgList">
					</image>
				</view>
			</view>
			<view class="public-trends-main-tools">
				<view class="public-trends-main-tools-item u-flex">
					<view class="public-trends-main-tools-item-left u-flex">
						<image src="../../static/img/publish/address.png" mode=""></image>
						<view class="public-trends-main-tools-item-left-content">
							<view class="" style="z-index: 2;position: relative;">
								所在位置
							</view>
						</view>
					</view>
					<view class="public-trends-main-tools-item-right u-flex">
						<view class="public-trends-main-tools-item-right-content">
							府东家园
						</view>
						<image src="../../static/img/arrow-right.png" mode=""></image>
					</view>
				</view>
				<view class="public-trends-main-tools-item u-flex">
					<view class="public-trends-main-tools-item-left u-flex">
						<image src="../../static/img/publish/at.png" mode=""></image>
						<view class="public-trends-main-tools-item-left-content">
							<view class="" style="z-index: 2;position: relative;">
								TA
							</view>
						</view>
					</view>
					<view class="public-trends-main-tools-item-right u-flex" @click="changeShowFriendList()">
						<view class="public-trends-main-tools-item-right-content blue">
							@王大锤 等2人
						</view>
						<image src="../../static/img/arrow-right.png" mode=""></image>
					</view>
				</view>
				<view class="public-trends-main-tools-item u-flex">
					<view class="public-trends-main-tools-item-left u-flex">
						<image src="../../static/img/publish/see.png" mode=""></image>
						<view class="public-trends-main-tools-item-left-content">
							<view class="" style="z-index: 2;position: relative;">
								谁可以看
							</view>
						</view>
					</view>
					<view class="public-trends-main-tools-item-right u-flex" @click="changeShowPrivacy()">
						<view class="public-trends-main-tools-item-right-content">
							{{privacyText}}
						</view>
						<image src="../../static/img/arrow-right.png" mode=""></image>
					</view>
				</view>
				<view class="public-trends-main-tools-item u-flex">
					<view class="public-trends-main-tools-item-left u-flex">
						<image src="../../static/img/publish/noname.png" mode=""></image>
						<view class="public-trends-main-tools-item-left-content">
							<view class="" style="z-index: 2;position: relative;">
								匿名发布
							</view>
						</view>
					</view>
					<view class="public-trends-main-tools-item-right u-flex">
						<view class="public-trends-main-tools-item-right-content">
							<u-switch v-model="post.anonymous" active-color="#FF516DFF">

							</u-switch>
						</view>

					</view>
				</view>
				<view class="public-trends-main-tools-item u-flex">
					<view class="public-trends-main-tools-item-left u-flex">
						<image src="../../static/img/publish/tags.png" mode=""></image>
						<view class="public-trends-main-tools-item-left-content">
							<view class="" style="z-index: 2;position: relative;">
								选择话题
							</view>
						</view>
					</view>
					<view class="public-trends-main-tools-item-right u-flex" @click="changeShowTags()">
						<view class="public-trends-main-tools-item-right-content tags u-flex"
							v-if="subjectTalkText!=''">
							<image src="../../static/img/find/tags.png" mode=""></image>
							<view class="">
								{{subjectTalkText}}
							</view>
						</view>
						<image src="../../static/img/arrow-right.png" mode=""></image>
					</view>
				</view>
			</view>
			<view class="public-trends-main-btn" @click="postFun()">
				<view class="public-btn" :class="allowPost?'public-btn-color':''">
					发布
				</view>
			</view>
		</view>
		<u-popup v-model="showFriendListCheck" mode="bottom" border-radius="20">
			<public-friendlistcheck></public-friendlistcheck>
		</u-popup>
		<u-popup v-model="showHiddenPerson" mode="center" border-radius="20">
			<view class="hidden-person">
				<image src="../../static/img/publish/hidden.png" style="width: 136rpx;height: 136rpx;" mode=""></image>
				<view class=""
					style="font-size: 28rpx;font-family: PingFang SC-Bold, PingFang SC;font-weight: bold;color: #2E3033;">
					随机身份
				</view>
				<view class="" style="margin: 32rpx 0;">
					此动态，系统会给你一个随机身份，随机身份下发布的动态只会出现在广场，不会出现在你的个人主页里
				</view>
				<view class="u-flex" style="justify-content: center;margin-bottom: 32rpx;">
					<image src="../../static/img/index/candy.png" style="width: 32rpx;height: 32rpx;" mode=""></image>
					<view class="" style="color: #FF516DFF;">
						将扣除10喜糖
					</view>
				</view>
				<view class="u-flex" style="justify-content: center;flex-direction: column;">
					<view class="public-btn-color public-btn" style="margin-bottom:30rpx"
						@click="changeShowHiddenPerson()">
						确定
					</view>
					<view class="public-btn" style="margin-bottom:30rpx" @click="cancelHiddenPerson()">
						取消
					</view>
				</view>
			</view>
		</u-popup>
		<u-popup v-model="showTags" mode="bottom" border-radius="20">
			<public-trendstagslist @getTagsId="getTagsId"></public-trendstagslist>
		</u-popup>
		<u-select v-model="showPrivacy" :list="privacyList" @confirm="getPrivacy"></u-select>
	</view>
</template>

<script>
	//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
	import navHeader from '../../components/nav-header/nav-header.vue'
	import publicFriendlistcheck from '../../components/public-friendlistcheck/public-friendlistcheck.vue'
	import publicTrendstagslist from '../../components/public-trendstagslist/public-trendstagslist.vue'
	export default {
		// 组件名称
		name: 'demo',
		// 组件参数 接收来自父组件的数据
		props: {},
		// 局部注册的组件,import引入的组件需要注入到对象中才能使用
		components: {
			navHeader,
			publicFriendlistcheck,
			publicTrendstagslist
		},
		// 组件状态值
		data() {
			return {
				text: "",
				imgList: ['https://picx.zhimg.com/80/v2-07a5d59b01f655ff15d62376e97ef2e2_400x224.webp?source=1940ef5c',
					'https://picx.zhimg.com/80/v2-07a5d59b01f655ff15d62376e97ef2e2_400x224.webp?source=1940ef5c'
				],
				privacyList: [{
					value: "1",
					label: "公开"
				}, {
					value: "2",
					label: "仅自己"
				}],
				subjectTalkList: [],
				friendsList: "",
				post: {
					type: "1",
					content: "",
					images: "https://picx.zhimg.com/80/v2-07a5d59b01f655ff15d62376e97ef2e2_400x224.webp?source=1940ef5c",
					address: "临沂市河东区沂蒙云谷",
					longitude: "118.36353",
					latitude: "35.11067",
					privacy: "1",
					subject_talk: "",
					anonymous: false,
					friends: "",
					province: "山东省",
					city: "临沂市",
					area: "河东区",
				},
				subjectTalkText: "",
				privacyText: "",
				showFriendListCheck: false,
				showHiddenPerson: false,
				showTags: false,
				showPrivacy: false,
				allowPost: false
			}
		},
		// 计算属性
		computed: {},
		// 侦听器
		watch: {
			'post.anonymous': {
				handler() {
					this.changeShowHiddenPerson()
				},
				deep: true
			},
			'post': {
				handler() {
					this.allowPost = this.canPost()
					console.log(this.allowPost)
				},
				deep: true
			},
			'text': {
				handler() {
					this.allowPost = this.canPost()
					console.log(this.allowPost)
				}
			}
		},
		// 组件方法
		methods: {
			changeShowFriendList() {
				this.showFriendListCheck = !this.showFriendListCheck
			},
			changeShowTags() {
				this.showTags = !this.showTags
			},
			changeShowPrivacy() {
				this.showPrivacy = !this.showPrivacy
			},
			changeShowHiddenPerson() {
				this.showHiddenPerson = !this.showHiddenPerson
			},
			cancelHiddenPerson() {
				this.changeShowHiddenPerson()
				this.post.anonymous = false
			},
			getTagsId(item) {
				this.post.subject_talk = item.id
				this.subjectTalkText = item.title

				this.changeShowTags()
			},
			getPrivacy(item) {
				this.post.privacy = item[0].value
				this.privacyText = item[0].label
				this.changeShowPrivacy()
			},
			canPost() {
				if (this.text.length == 0) {
					return '请输入正文'
				}
				if (this.post.latitude == '' || this.post.longitude == '') {
					return '请选择地址'
				}
				return true
			},
			postFun() {
				let that = this;
				if (that.canPost() == true) {
					let item = {}
					item = JSON.parse(JSON.stringify(that.post))
					item.anonymous = item.anonymous ? '1' : '0'
					item.content = that.text
					console.log(item)
					that.$http('public.pushTrends', item, '').then(res => {
						uni.showToast({
							title: res.info,
							icon: 'none',
							position: 'top'
						});
						this.$Router.back()
					});
				} else {
					uni.showToast({
						title: that.canPost(),
						icon: 'none',
						position: 'top'
					});
				}
			}
		},
		// 以下是生命周期钩子   注：没用到的钩子请自行删除
		/**
		 * 在实例初始化之后，组件属性计算之前，如data属性等
		 */
		beforeCreate() {},
		/**
		 * 组件实例创建完成，属性已绑定，但DOM还未生成，$ el属性还不存在
		 */
		created() {

		},
		/**
		 * 在挂载开始之前被调用：相关的 render 函数首次被调用。
		 */
		beforeMount() {},
		/**
		 * el 被新创建的 vm.$ el 替换，并挂载到实例上去之后调用该钩子。
		 * 如果 root 实例挂载了一个文档内元素，当 mounted 被调用时 vm.$ el 也在文档内。
		 */
		mounted() {},
		/**
		 * 数据更新时调用，发生在虚拟 DOM 重新渲染和打补丁之前。
		 * 你可以在这个钩子中进一步地更改状态，这不会触发附加的重渲染过程。
		 */
		beforeUpdate() {},
		/**
		 * 由于数据更改导致的虚拟 DOM 重新渲染和打补丁，在这之后会调用该钩子。
		 * 当这个钩子被调用时，组件 DOM 已经更新，所以你现在可以执行依赖于 DOM 的操作。
		 */
		updated() {},
		/**
		 * keep-alive 组件激活时调用。 仅针对keep-alive 组件有效
		 */
		activated() {},
		/**
		 * keep-alive 组件停用时调用。 仅针对keep-alive 组件有效
		 */
		deactivated() {},
		/**
		 * 实例销毁之前调用。在这一步，实例仍然完全可用。
		 */
		beforeDestroy() {},
		/**
		 * Vue 实例销毁后调用。调用后，Vue 实例指示的所有东西都会解绑定，
		 * 所有的事件监听器会被移除，所有的子实例也会被销毁。
		 */
		destroyed() {}
	}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<!--使用了scoped属性之后，父组件的style样式将不会渗透到子组件中，-->
<!--然而子组件的根节点元素会同时被设置了scoped的父css样式和设置了scoped的子css样式影响，-->
<style scoped lang="scss">
	.public-trends {
		width: 100%;
		height: 100%;
		background: linear-gradient(#F1EFFFFF 0%, #FFFFFF 20%);
		padding-top: $nav-top-height;

		&-main {
			padding: 0 32rpx;

			&-input {
				width: 100%;
				margin: 32rpx 0;
				padding-bottom: 32rpx;
				border-bottom: solid 1rpx #F5F5F5;

				&-max {
					font-size: 24rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 500;
					color: #8A9199;
					text-align: right;
				}

				textarea {
					width: 100%;
					height: 180rpx;
					font-size: 28rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					color: #2E3033;
					line-height: 22rpx;
				}
			}

			&-pic {
				&-item {
					image {
						border-radius: 18rpx;
						margin-right: 18rpx;
					}
				}
			}

			&-tools {
				&-item {
					justify-content: space-between;
					height: 100rpx;
					border-bottom: solid 1rpx #F5F5F5FF;

					&-left {
						image {
							margin-right: 10rpx;
							width: 32rpx;
							height: 32rpx;
						}

						&-content {
							position: relative;
						}

						&-content:after {
							content: '';
							display: block;
							width: 100%;

							position: absolute;
							left: 0;
							bottom: 0;
							height: 8rpx;
							border-radius: 10rpx;
							background: #e7e5ffFF;
							z-index: 0;
						}
					}

					&-right {
						image {
							width: 40rpx;
							height: 40rpx;
							margin-left: 10rpx;
						}

						&-content {
							font-size: 28rpx;
							font-family: PingFang SC-Medium, PingFang SC;
							color: #8A9199;
						}

						.blue {
							font-size: 28rpx;
							font-family: PingFang SC-Medium, PingFang SC;
							font-weight: 500;
							color: #0085FF;
						}

						.tags {
							height: 48rpx;
							background: #F1F6FF;
							border-radius: 31rpx;
							font-size: 24rpx;
							font-family: PingFang SC-Medium, PingFang SC;
							color: #0085FF;
							padding: 0 16rpx;
							line-height: 48rpx;

							image {
								width: 28rpx;
								height: 28rpx;
							}
						}
					}
				}
			}

			&-btn {
				.public-btn {
					margin: 0 auto;
					margin-top: 60rpx;
				}
			}
		}

		.hidden-person {
			text-align: center;
			padding: 60rpx 80rpx;
		}
	}
</style>
